#include <iostream>
#include <list>

using namespace std;
// list 反转和排序:将容器中的元素反转，以及将容器中的数据进行排序
//函数原型：
//1、reverse();      //反转链表
//2、sort();         //链表排序

void printL(const list<int> &l) {
    for (list<int>::const_iterator it = l.begin(); it != l.end(); ++it) {
        cout << *it << " ";
    }
    cout << endl;
}

bool myCompare(int val1, int val2) {
    return val1 > val2;
}

void test1() {
    cout << "反转前:" << endl;
    list<int> l;
    l.push_back(90);
    l.push_back(30);
    l.push_back(20);
    l.push_back(70);
    printL(l);

    cout << "反转后:" << endl;
    l.reverse();//反转容器的元素
    printL(l);


}

void test2() {
    cout << "排序前:" << endl;
    list<int> l;
    l.push_back(20);
    l.push_back(10);
    l.push_back(50);
    l.push_back(40);
    l.push_back(30);
    printL(l);

    cout << "从小到大排序后:" << endl;
    l.sort();//默认的排序规则 从小到大
    printL(l);

    cout << "从大到小排序后:" << endl;
    l.sort(myCompare);//指定规则 从大到小
    printL(l);
}

int main() {
    test1();
    cout << "=========" << endl;
    test2();
    return 0;
}